package com.zhuchaooasystem.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhuchaooasystem.R;



/**
 * Created by sunquan on 16/7/25.
 */
public class DialogUtils {


    /**
     * 网络加载
     * @throws
     * @Title: LoadingDialog
     * @param: @param context
     * @param: @return
     * @return: Dialog
     */

    public static Dialog LoadingDialog(Context context, String hingstr) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dlg_loading, null);

        TextView loadtv = (TextView) view.findViewById(R.id.loading_tv);
        if (hingstr == null) {
            loadtv.setVisibility(View.GONE);
        } else {
            loadtv.setVisibility(View.VISIBLE);
            loadtv.setText(hingstr);
        }
        final Dialog dialog = new Dialog(context, R.style.dialog_BOT_style_no);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.CENTER);

        WindowManager windowManager = ((Activity) context).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = (int) (display.getWidth());
        dialog.getWindow().setAttributes(params);

        dialog.onWindowAttributesChanged(params);
        dialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                        | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
        dialog.setContentView(view);


        return dialog;

    }

    public static Dialog LoadingDialog(Context context) {


        return LoadingDialog(context, null);

    }


}
